
Imports System.Data
Imports System.Data.SqlClient


Namespace Kardex
Public Class OrdenCompra

public Function Listar(OrdenCompraId as integer) as Entity.Kardex.OrdenCompra

Dim strNameProcedure as string = "up_Kar_OrdenCompra_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Kardex.OrdenCompra
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@OrdenCompraId", SqlDbType.Int)).Value =OrdenCompraId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Kardex.OrdenCompra
With objEnt
		.OrdenCompraId = sqlReader("OrdenCompraId").ToString
		.ProveedorId = sqlReader("ProveedorId").ToString
		.TipoDocumento = sqlReader("TipoDocumento").ToString
		.NumeroDocumento = sqlReader("NumeroDocumento").ToString
		.AlmacenId = sqlReader("AlmacenId").ToString
		.Fecha = sqlReader("Fecha").ToString
		.SubTotal = sqlReader("SubTotal").ToString
		.IGV_PORCENTAJE = sqlReader("IGV_PORCENTAJE").ToString
		.IGV = sqlReader("IGV").ToString
		.Total = sqlReader("Total").ToString
		.Descripcion = sqlReader("Descripcion").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		OrdenCompraId as Integer, _
		ProveedorId as Integer, _
		TipoDocumento as Integer, _
		NumeroDocumento as String, _
		AlmacenId as Integer, _
		Fecha as Long, _
		SubTotal as Double, _
		IGV_PORCENTAJE as Double, _
		IGV as Double, _
		Total as Double, _
		Descripcion as String) _
as  Entity.Kardex.OrdenCompraCol

Dim strNameProcedure as string = "up_Kar_OrdenCompra_listar"
dim objCol as   entity.Kardex.OrdenCompraCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@OrdenCompraId",SqlDbType.INT)).Value =OrdenCompraId
 cmd.Parameters.Add(New SqlParameter("@ProveedorId",SqlDbType.INT)).Value =ProveedorId
 cmd.Parameters.Add(New SqlParameter("@TipoDocumento",SqlDbType.INT)).Value =TipoDocumento
 cmd.Parameters.Add(New SqlParameter("@NumeroDocumento",SqlDbType.VARCHAR,50)).Value =NumeroDocumento
 cmd.Parameters.Add(New SqlParameter("@AlmacenId",SqlDbType.INT)).Value =AlmacenId
 cmd.Parameters.Add(New SqlParameter("@Fecha",SqlDbType.BIGINT)).Value =Fecha
 cmd.Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 cmd.Parameters.Add(New SqlParameter("@IGV_PORCENTAJE",SqlDbType.DECIMAL,18)).Value =IGV_PORCENTAJE
 cmd.Parameters.Add(New SqlParameter("@IGV",SqlDbType.DECIMAL,18)).Value =IGV
 cmd.Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 cmd.Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,250)).Value =Descripcion
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iOrdenCompraId as integer = dr.GetOrdinal("OrdenCompraId")
		dim iProveedorId as integer = dr.GetOrdinal("ProveedorId")
		dim iTipoDocumento as integer = dr.GetOrdinal("TipoDocumento")
		dim iNumeroDocumento as integer = dr.GetOrdinal("NumeroDocumento")
		dim iAlmacenId as integer = dr.GetOrdinal("AlmacenId")
		dim iFecha as integer = dr.GetOrdinal("Fecha")
		dim iSubTotal as integer = dr.GetOrdinal("SubTotal")
		dim iIGV_PORCENTAJE as integer = dr.GetOrdinal("IGV_PORCENTAJE")
		dim iIGV as integer = dr.GetOrdinal("IGV")
		dim iTotal as integer = dr.GetOrdinal("Total")
		dim iDescripcion as integer = dr.GetOrdinal("Descripcion")
		dim i_usu_cre as integer = dr.GetOrdinal("_usu_cre")
		dim i_fec_cre as integer = dr.GetOrdinal("_fec_cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_fec_mod as integer = dr.GetOrdinal("_fec_mod")
		dim i_flg_eli as integer = dr.GetOrdinal("_flg_eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Kardex.OrdenCompraCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Kardex.OrdenCompra
dr.GetValues(values)

		objEnt.OrdenCompraId = values(iOrdenCompraId)
		objEnt.ProveedorId = values(iProveedorId)
		objEnt.TipoDocumento = values(iTipoDocumento)
		objEnt.NumeroDocumento = values(iNumeroDocumento)
		objEnt.AlmacenId = values(iAlmacenId)
		objEnt.Fecha = values(iFecha)
		objEnt.SubTotal = values(iSubTotal)
		objEnt.IGV_PORCENTAJE = values(iIGV_PORCENTAJE)
		objEnt.IGV = values(iIGV)
		objEnt.Total = values(iTotal)
		objEnt.Descripcion = values(iDescripcion)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		OrdenCompraId as Integer, _
		ProveedorId as Integer, _
		TipoDocumento as Integer, _
		NumeroDocumento as String, _
		AlmacenId as Integer, _
		Fecha as Long, _
		SubTotal as Double, _
		IGV_PORCENTAJE as Double, _
		IGV as Double, _
		Total as Double, _
		Descripcion as String, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompra_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@OrdenCompraId",SqlDbType.INT)).Value =OrdenCompraId
 .Parameters.Add(New SqlParameter("@ProveedorId",SqlDbType.INT)).Value =ProveedorId
 .Parameters.Add(New SqlParameter("@TipoDocumento",SqlDbType.INT)).Value =TipoDocumento
 .Parameters.Add(New SqlParameter("@NumeroDocumento",SqlDbType.VARCHAR,50)).Value =NumeroDocumento
 .Parameters.Add(New SqlParameter("@AlmacenId",SqlDbType.INT)).Value =AlmacenId
 .Parameters.Add(New SqlParameter("@Fecha",SqlDbType.BIGINT)).Value =Fecha
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@IGV_PORCENTAJE",SqlDbType.DECIMAL,18)).Value =IGV_PORCENTAJE
 .Parameters.Add(New SqlParameter("@IGV",SqlDbType.DECIMAL,18)).Value =IGV
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,250)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		OrdenCompraId as Integer, _
		ProveedorId as Integer, _
		TipoDocumento as Integer, _
		NumeroDocumento as String, _
		AlmacenId as Integer, _
		Fecha as Long, _
		SubTotal as Double, _
		IGV_PORCENTAJE as Double, _
		IGV as Double, _
		Total as Double, _
		Descripcion as String, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompra_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@OrdenCompraId",SqlDbType.INT)).Value =OrdenCompraId
 .Parameters.Add(New SqlParameter("@ProveedorId",SqlDbType.INT)).Value =ProveedorId
 .Parameters.Add(New SqlParameter("@TipoDocumento",SqlDbType.INT)).Value =TipoDocumento
 .Parameters.Add(New SqlParameter("@NumeroDocumento",SqlDbType.VARCHAR,50)).Value =NumeroDocumento
 .Parameters.Add(New SqlParameter("@AlmacenId",SqlDbType.INT)).Value =AlmacenId
 .Parameters.Add(New SqlParameter("@Fecha",SqlDbType.BIGINT)).Value =Fecha
 .Parameters.Add(New SqlParameter("@SubTotal",SqlDbType.DECIMAL,18)).Value =SubTotal
 .Parameters.Add(New SqlParameter("@IGV_PORCENTAJE",SqlDbType.DECIMAL,18)).Value =IGV_PORCENTAJE
 .Parameters.Add(New SqlParameter("@IGV",SqlDbType.DECIMAL,18)).Value =IGV
 .Parameters.Add(New SqlParameter("@Total",SqlDbType.DECIMAL,18)).Value =Total
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,250)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, OrdenCompraId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Kar_OrdenCompra_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@OrdenCompraId", SqlDbType.Int)).Value =OrdenCompraId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

